package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.StoreIn;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.StoreInMapper;
import com.ruoyi.system.service.StoreInService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: ruohao
 * @Date: 2023/10/13
 **/
@Service
public class StoreInServiceImpl implements StoreInService {
    @Resource
    private StoreInMapper storeInMapper;

    @Override
    public List<StoreIn> selectList(StoreIn storeIn) {
        return storeInMapper.selectList(storeIn);
    }

    @Override
    public Boolean update(StoreIn storeIn) {
        return storeInMapper.update(storeIn) == 1;
    }

    @Override
    public Boolean deleteById(Long id) {
        return storeInMapper.deleteById(id) == 1;
    }

    @Override
    public Boolean create(StoreIn storeIn) {
        if (StringUtils.isBlank(storeIn.getArea())) {
            SysUser user = SecurityUtils.getLoginUser().getUser();
            storeIn.setArea(user.getLocation());
//            throw new BaseException("错误，园区为空");
        }
        if (StringUtils.isBlank(storeIn.getArea())) {
            throw new BaseException("错误，登录人园区为空");
        }
        return storeInMapper.insert(storeIn) == 1;
    }

    @Override
    public StoreIn selectById(Long id) {
        return storeInMapper.selectById(id);
    }

    @Override
    public List<StoreIn> selectTenList() {
        return storeInMapper.selectTenList();
    }
}
